package com.rerun.controller;

import com.rerun.common.bean.Rest;
import com.rerun.common.util.ExcelImport;
import com.rerun.entity.vo.StudentExcelDataVo;
import com.rerun.service.IExcelService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.List;

/**
 * Excel数据处理
 *
 * @author dax.
 * @version v1.0
 * @since 2017 /9/28 15:59
 */
@Controller
@RequestMapping("/excel")
public class ExcelController {
   @Resource
   private IExcelService iExcelService;


    /**
     * Excel.
     *
     * @param file the files
     * @return the rest
     * @throws Exception the exception
     */
    @RequestMapping("/importExcels")
    @ResponseBody
    public Rest excelImport(@RequestParam MultipartFile file) throws Exception {
        InputStream inputStream = file.getInputStream();
        List<Object> studentExcelDataVos = ExcelImport.importExcel(StudentExcelDataVo.class, inputStream);
        return iExcelService.dataInsert(studentExcelDataVos);
    }

}
